#import "GPSLocation.h"

/**
 * Contains longitude and latitude for a GPS coordinate.
 * 
 * @author      Justin Hollander
 * @version     0.7.0     
 * @since       0.1.0
 * @see         PersistentDataType
 */
@implementation GPSLocation

@synthesize longitude;
@synthesize latitude;

/**
 * Initialize the GPS location with coordinates.
 * 
 * @param  lat  latitude
 * @param  lon  longitude
 * @return      initialized GPS location
 */
-(id)initWithDetails:(double)lat lon:(double)lon
{
	if(self = [super init])
	{
		self.longitude = lon; //sets custom longitude coordinate
		self.latitude = lat; //sets custom latitude coordinate
	}
	
	return self;
}

/**
 * Initializes the GPS location from archive.
 *
 * @param decoder  the NSCoder used for decoding
 * @return         the GPS location decoded from archive
 */
-(id)initWithCoder:(NSCoder*)decoder{
	
	if ((self = [self init]) && ([decoder allowsKeyedCoding]))  {	
		self.longitude = [decoder decodeDoubleForKey:@"GPSLocationLongitude"];
		self.latitude = [decoder decodeDoubleForKey:@"GPSLocationLatitude"];
	}
	
	return self;
}

/**
 * Initialize the GPS location with another one.
 * 
 * @param  copy  the other GPS location to copy
 * @return       initialized GPS location
 */
-(id)initWithParam:(GPSLocation*)copy
{
	if(self = [super init])
	{
		self.longitude = copy.longitude;
		self.latitude = copy.latitude;
	}
	
	return self;
}

/**
 * Default constructor
 */
-(id)init
{
	if(self = [super init])
	{
		self.longitude = 0.0;
		self.latitude = 0.0;
	}
	
	return self;
}

/**
 * Encodes the GPS location for archiving options.
 *
 * @param encoder  the NSCoder used for encoding
 */
-(void)encodeWithCoder:(NSCoder*)encoder{
	
	if([encoder allowsKeyedCoding]){
		[encoder encodeDouble:self.longitude forKey:@"GPSLocationLongitude"];
		[encoder encodeDouble:self.latitude forKey:@"GPSLocationLatitude"];
	}
}

/**
 * Compute a unique key for the GPS location.
 *
 * @return  the unique key
 */
-(NSString*) getKey{
	return [NSString stringWithFormat:@"%f%f",longitude, latitude];
}

@end
